package com.funny;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.funny.stock.data.vo.RealtimeStockData;

import java.util.ArrayList;
import java.util.List;

/**
 * @author pengl
 * @date 2020/11/07
 **/
public class T2 {
    public static void main(String[] args) {

        String text = "ne210fc68e1163ac({\"MARKET_HS\": {\"status\": \"\\u5df2\\u6536\\u76d8\", \"update\": \"2020-11-10 15:02:02\"} });";

//        int firstIndex = text.indexOf("{");
//        int lastIndex = text.lastIndexOf("}");
////        if(firstIndex == -1 || lastIndex == -1) {
////            System.out.println("error");
////        }
//        String json = text.substring(firstIndex, lastIndex + 1);
//        System.out.println(json);
//
//        JSONObject jsonObject = JSON.parseObject(json);
//        JSONObject data = jsonObject.getJSONObject("MARKET_HS");
//        if(data != null){
//            String status = data.getString("status");
//            String time = data.getString("update");
//            System.out.println(status);
//            System.out.println(time);
//        }


        String json = "{\"1002151\":{\"code\": \"1002151\", \"percent\": -0.008423, \"high\": 57.75, \"askvol3\": 5100, \"askvol2\": 12800, \"askvol5\": 3800, \"askvol4\": 6700, \"price\": 56.51, \"open\": 57.0, \"bid5\": 56.46, \"bid4\": 56.47, \"bid3\": 56.48, \"bid2\": 56.49, \"bid1\": 56.5, \"low\": 56.05, \"updown\": -0.48, \"type\": \"SZ\", \"bidvol1\": 84600, \"status\": 0, \"bidvol3\": 9901, \"bidvol2\": 6800, \"symbol\": \"002151\", \"update\": \"2020/11/10 15:59:58\", \"bidvol5\": 1900, \"bidvol4\": 400, \"volume\": 16197355, \"askvol1\": 108208, \"ask5\": 56.55, \"ask4\": 56.54, \"ask1\": 56.51, \"name\": \"\\u5317\\u6597\\u661f\\u901a\", \"ask3\": 56.53, \"ask2\": 56.52, \"arrow\": \"\\u2193\", \"time\": \"2020/11/10 15:59:54\", \"yestclose\": 56.99, \"turnover\": 919105402.21},\"0600036\":{\"code\": \"0600036\", \"percent\": 0.016035, \"high\": 44.38, \"askvol3\": 51100, \"askvol2\": 4000, \"askvol5\": 29900, \"askvol4\": 41600, \"price\": 43.72, \"open\": 43.77, \"bid5\": 43.68, \"bid4\": 43.69, \"bid3\": 43.7, \"bid2\": 43.71, \"bid1\": 43.72, \"low\": 43.4, \"updown\": 0.69, \"type\": \"SH\", \"symbol\": \"600036\", \"status\": 0, \"ask4\": 43.76, \"bidvol3\": 5120, \"bidvol2\": 27781, \"bidvol1\": 48424, \"update\": \"2020/11/10 15:59:58\", \"bidvol5\": 26300, \"bidvol4\": 3838, \"yestclose\": 43.03, \"askvol1\": 1900, \"ask5\": 43.77, \"volume\": 56207925, \"ask1\": 43.73, \"name\": \"\\u62db\\u5546\\u94f6\\u884c\", \"ask3\": 43.75, \"ask2\": 43.74, \"arrow\": \"\\u2191\", \"time\": \"2020/11/10 15:59:57\", \"turnover\": 2461059112} }";

        List<RealtimeStockData> dataList = new ArrayList<>();

        JSONObject jsonObject = JSON.parseObject(json);
        for (String key : jsonObject.keySet()) {
            JSONObject valueObj = jsonObject.getJSONObject(key);
            RealtimeStockData stockData = valueObj.toJavaObject(RealtimeStockData.class);
            dataList.add(stockData);
        }

        System.out.println(dataList.size());

//        LocalDate localDate = LocalDate.now();
//        String date = localDate.toString();
//        System.out.println(date);
//
//        String toString = LocalDate.parse(date).minusDays(1).toString();
//        System.out.println(toString);
    }
}
